#!/usr/bin/env python
# -*- coding: GB2312 -*-

"""Check new mails at gmail.com

add this line to cron, using 'crontab -e':
*/20 * * * * /home/xyb/bin/checkgmail.py 2> /dev/null
"""

__revision__ = '0.1'

import sys
sys.path.append('/')

def loop():
    import time
    from gmail import GmailClient
    c = GmailClient()
    c.login('test','123456')
    while True:
        print time.asctime(), len(c.get_inbox_conversations(is_unread=True))
        time.sleep(60)

def scan():
    import time
    from gmail import GmailClient
    all=(('test','123456'),)
    for u,p in all:
        c = GmailClient()
        c.login(u,p)
        new=len(c.get_inbox_conversations(is_unread=True))
        if new:
            print time.asctime(), u+'@gmail.com', new
        del c

def main():
    import sys
    if len(sys.argv)==1:
        scan()

if '__main__'==__name__:
    main()
